package client;

import entities.GameObject;
import entities.Property;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;

/**
 *
 * @author casshern
 */
public class Status extends JPanel {

    private JLabel label1;// time or the name of the entity
    private JLabel label2;//total money and entity's blood
    private int playerID;
    private int remainingTime;
    private int money;

    public Status(int playerID) {
        this.playerID = playerID;
        label1 = new JLabel();
        label1.setPreferredSize(new Dimension(180, 28));
        label2 = new JLabel();
        label2.setPreferredSize(new Dimension(180, 28));

        this.setPreferredSize(new Dimension(200, 110));
        this.setBackground(Color.GRAY);
        this.setBorder(BorderFactory.createTitledBorder("Status"));
        this.setLayout(new GridBagLayout());
        GridBagConstraints c = new GridBagConstraints();
        c.anchor = GridBagConstraints.WEST;
        c.gridwidth = GridBagConstraints.REMAINDER;
        c.insets = new Insets(1, 10, 5, 0);
        this.add(label1, c);
        this.add(label2, c);
    }

    public void showObjInfo(GameObject obj) {
        int type = obj.getType();
        String entityName = null;
        switch (type) {
            case GameObject.ASTEROID0:
            case GameObject.ASTEROID1:
            case GameObject.ASTEROID2:
            case GameObject.ASTEROID3:
                entityName = " Asteroid";
                break;
            case GameObject.ATTACK:
                entityName = " Attacker";
                break;
            case GameObject.LASER:
                entityName = " Laser";
                break;
            case GameObject.MINER:
                entityName = " Miner";
                break;
            case GameObject.POWERSTATION:
                entityName = " PowerStation";
                break;
        }
        label1.setText("Entity's Name:  " + entityName);
        label2.setText("Current Health: " + obj.getCurrentHealth() + " / " + obj.getMaxHealth());
    }

    public void showGameInfo() {
        String minute = String.valueOf(remainingTime / 60);
        if (minute.length() < 2) {
            minute = "0" + minute;
        }
        String second = String.valueOf(remainingTime % 60);
        if (second.length() < 2) {
            second = "0" + second;
        }
        label1.setText("Remaining Time: " + minute + ":" + second);
        label2.setText("Total Money: " + money);
    }

    public void statusUpdate(Property property) {
        remainingTime = property.getType();
        if (playerID == 1) {
            money = property.getX();
        } else {
            money = property.getY();
        }
    }
}
